package com.moto.mapper;

import com.moto.entity.Bolg;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moto.entity.Favorite;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zy
 * @since 2023-08-31
 */
@Mapper
public interface FavoriteMapper extends BaseMapper<Favorite> {

    @Select("SELECT b.bolg_title,b.bolg_author,b.imgs,b.bolg_watch FROM bolg b LEFT JOIN favorite f ON b.bolg_id=f.bolg_id JOIN user u on f.u_id=u.id WHERE u.id=#{id}")
    List<Bolg> favoriteList(int id);

    /**
     * 收藏列表增加
     * @param
     * @param
     */
    @Transactional
    @Insert("insert into favorite (u_id,bolg_id) values (#{uId},#{bolgId})")
    void addFavorite(Favorite favorite);
}
